<?
//先通过dirname(__FILE__)获取到当前文件绝对路径，然后再按具体情况用..去控制找到templates文件夹下的header.php
include dirname(__FILE__)."/../templates/header.php";
?>

<script type="text/javascript" src="<? echo base_url() ?>js/ztree/jquery.ztree.all-3.2.js"></script>

<script type="text/javascript">

//确认添加
function CheckAdd()
{
	if(! abhxCommonValidate($("#addForm"))){
		return false;
	}
	return true ;
}

//确认修改
function CheckUpdate(id)
{
	$("#id_update").val(id);
	$("#name_update").val( $("#name_" + id).val() );
	$("#category_type_id_update").val( $("#category_type_id_" + id).val() );
	$("#order_update").val( $("#order_" + id).val() );

	if(! abhxCommonValidate($("#updateForm"))){
		return false;
	}
	$("#updateForm").get(0).submit();
}

//确认删除
function SureDel(id , parent_category_id )
{
	if(confirm("确认删除该栏目吗?"))
	{
		document.location.href = "<? echo base_url() ?>index.php/category/delete/" + id + "/" + parent_category_id ;
	}
}

</script>

<!--修改form，内容由js动态传入-->
<form id="updateForm" method="post" action="<? echo base_url() ?>index.php/category/saveOrUpdate" >
	<!--父栏目id-->
	<input type="hidden" name="parent_category_id" value="<? echo $category_id ?>" />
	<!--栏目id-->
	<input type="hidden" name="id_update" id="id_update"/>
	<!--栏目类型id-->
	<input type="hidden" name="category_type_id_update" id="category_type_id_update"/>
	<!--栏目名称-->
	<input type="hidden" name="name_update" id="name_update"
		abhxValid="true" abhxValidType="text,required" abhxValidName="子栏目名称"/>
	<!--栏目显示顺序-->
	<input type="hidden" name="order_update" id="order_update"
		abhxValid="true" abhxValidType="int,required" abhxValidName="显示顺序"/>
</form>

<table border="0" cellspacing="1" cellpadding="3" align="center" class="title">
<tr>
	<td>管理子栏目</td>
</tr>
</table>
<table border="0" cellspacing="1" cellpadding="3" align="center" class="dataList">
	<tr>
		<th width="40%" align="center" valign="middle">子栏目名称</th>
		<th width="20%" align="center" valign="middle">展示类型</th>
		<th width="20%" align="center" valign="middle">显示顺序</th>
		<th width="20%" align="center" valign="middle">操作</th>
	</tr>

<?
	$cnt = 0 ;
	foreach($result_array as $row){
		$cnt++;
?>
	<tr>
	  <td align="center" valign="middle">
			<input type="text" id="name_<? echo $row['id'] ?>" size="22" value="<? echo $row['name'] ?>"/>
      </td>
      <td align="center" valign="middle">
		  <select id="category_type_id_<? echo $row['id'] ?>">
		  	<option value="">请选择</option>
		    <option value="1" <? if($row['category_type_id'] == "1"){ echo "selected" ; } ?>>列表</option>
		    <option value="2" <? if($row['category_type_id'] == "2"){ echo "selected" ; } ?>>单篇</option>
		    <option value="3" <? if($row['category_type_id'] == "3"){ echo "selected" ; } ?>>图片</option>
		  </select>
	  </td>
	  <td align="center" valign="middle">
			<input type="text" id="order_<? echo $row['id'] ?>" size="5" value="<? echo $row['order_no'] ?>"
			  onKeyUp="if (isNaN(this.value)) this.value=<? echo $row['order_no'] ?>"/>
	  </td>
	  <td align="center" valign="middle">
			<input type="button" name="btnSubmit" value=" 修 改 " title="保存修改内容" onClick="CheckUpdate('<? echo $row['id'] ?>')">&nbsp;
			<input type="button" name="btnDel" value=" 删 除 " title="删除该子栏目及以下的信息" onClick="SureDel('<? echo $row['id'] ?>','<? echo $row['parent_category_id'] ?>')">
	  </td>
    </tr>
<?
	}
	if($cnt==0){
?>
	<tr>
		<td colspan="5">栏目下还没有子栏目</td>
	</tr>
<?
	}
?>
</table>

<table cellspacing="1" cellpadding="3" class="title" class="title">
	<tr>
		<td>添加子栏目</td>
	</tr>
</table>
<form id="addForm" method="post" action="<? echo base_url() ?>index.php/category/saveOrUpdate" onSubmit="return CheckAdd();">
	<!--父栏目id-->
	<input type="hidden" name="parent_category_id" value="<? echo $category_id ?>" />

	<table border="0" cellspacing="1" cellpadding="3" align="center" class="dataList">
		<tr>
			<th width="40%" align="center" valign="middle">子栏目名称</th>
			<th width="20%" align="center" valign="middle">展示类型</th>
			<th width="20%" align="center" valign="middle">显示顺序</th>
			<th width="20%" align="center" valign="middle">操作</th>
		</tr>
		<tr>
			<td align="center" valign="middle">
				<input type="text" name="name_add" size="22" maxlength="50"
				 abhxValid="true" abhxValidType="text,required" abhxValidName="子栏目名称"/>
			</td>
			<td align="center" valign="middle">

				<select name="category_type_id_add" abhxValid="true" abhxValidType="required" abhxValidName="展示类型">
				   <option value="">请选择</option>
				   <option value="1">列表</option>
				   <option value="2">单篇</option>
				   <option value="3">图片</option>
				</select>
			</td>
			<td align="center" valign="middle">
				<input type="text" name="order_add" size="5"
				 abhxValid="true" abhxValidType="int,required" abhxValidName="显示顺序"/>
			</td>
			<td align="center" valign="middle">
				<input type="submit" name="Submit" value=" 添 加 " title="确认添加"/>&nbsp;
				<input type="reset" name="btnReset" value=" 重 置 " title="清空所输入的内容"/>
			</td>
		</tr>
	</table>
</form>

<table cellspacing="1" cellpadding="3" class="title">
	<tr>
		<td>操作注意事项</td>
	</tr>
</table>
<table border="0" cellspacing="1" cellpadding="3">
	<tr>
		<td >·请注意"栏目名称"不要含有 ' " % < > 等非法字符。<br>
			·增加类别且选中"是否显示"后，这些类别将会被列出前台中，序号大的排前面。<br>
		</td>
	</tr>
</table>

<? if($info != "no"){
?>
<script type='text/javascript'>
	alert("<? echo $info ?>");

	var treeObj = window.parent.parent.treeFrame.zTree ;

	var nodes = treeObj.getNodesByParam("id", "<? echo $category_id ?>", null);

	if (nodes.length>0) {
		//刷新当前栏目
		treeObj.reAsyncChildNodes(nodes[0], "refresh");
	}else{
		//获取根目录
		nodes = treeObj.getNodesByParam("id", "0", null);
		treeObj.reAsyncChildNodes(nodes[0], "refresh");
	}

</script>
<? } ?>

